//
//  CYGHotsSelectionView.m
//  CYGHuntForCity
//
//  Created by cygarm on 16/3/7.
//  Copyright © 2016年 cygarm. All rights reserved.
//

#import "CYGHotsSelectionView.h"

@interface CYGHotsSelectionView ()

@property (weak, nonatomic) IBOutlet UIButton *btn1;
@property (weak, nonatomic) IBOutlet UIButton *btn2;
@property (weak, nonatomic) IBOutlet UIButton *btn3;
@property (weak, nonatomic) IBOutlet UIButton *btn4;

@property (strong, nonatomic) UIView *line1;
@property (strong, nonatomic) UIView *line2;
@property (strong, nonatomic) UIView *line3;

@end

@implementation CYGHotsSelectionView

- (instancetype)initWithFrame:(CGRect)frame {
	if (self = [super initWithFrame:frame]) {
		self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
		[self setupUI];
	}
	return self;
}

- (void)awakeFromNib {
	[super awakeFromNib];
	[self setupUI];
}

- (void)setupUI {
	self.layer.masksToBounds = YES;
	self.layer.cornerRadius = CYGCornerRadius;
	self.bigView.alpha = CYGHotsSelectionViewAlpha;

	self.listBtn.backgroundColor = self.bigView.backgroundColor;
	self.listBtn.alpha = self.bigView.alpha;
	self.listBtn.layer.masksToBounds = YES;
	self.listBtn.layer.cornerRadius = CYGCornerRadius;
	
	self.btn1.tag = CYGHotsSelectionViewTagBtn1;
	self.btn2.tag = CYGHotsSelectionViewTagBtn2;
	self.btn3.tag = CYGHotsSelectionViewTagBtn3;
	self.btn4.tag = CYGHotsSelectionViewTagBtn4;
	self.listBtn.tag = CYGHotsSelectionViewTagBtnList;
		
	self.line1 = [[UIView alloc] init];
	self.line2 = [[UIView alloc] init];
	self.line3 = [[UIView alloc] init];
	self.line1.backgroundColor = [UIColor grayColor];
	self.line2.backgroundColor = [UIColor grayColor];
	self.line3.backgroundColor = [UIColor grayColor];
	self.line1.alpha = 0.8;
	self.line2.alpha = 0.8;
	self.line3.alpha = 0.8;
	
	[self.bigView addSubview:self.line1];
	[self.bigView addSubview:self.line2];
	[self.bigView addSubview:self.line3];
}

- (void)layoutSubviews {	
	CGFloat lineH = self.frame.size.height*0.4;
	CGFloat lineY = self.frame.size.height*0.3;
		
	self.line1.frame = CGRectMake(self.btn2.frame.origin.x, lineY, 1, lineH);
	self.line2.frame = CGRectMake(self.btn3.frame.origin.x, lineY, 1, lineH);
	self.line3.frame = CGRectMake(self.btn4.frame.origin.x, lineY, 1, lineH);
}

- (IBAction)btnClick:(id)sender {
	UIButton *btn = (UIButton *)sender;
	if (btn == self.selectedBtn) {
		self.selectedBtn = nil;
		btn.selected = NO;
		btn.backgroundColor = self.bigView.backgroundColor;
		[self.delegate hotsSelectionViewBtnClick:btn];
	} else {
		self.selectedBtn.selected = NO;
		self.selectedBtn.backgroundColor = self.bigView.backgroundColor;
		[self.delegate hotsSelectionViewBtnClick:self.selectedBtn];
		
		btn.selected = YES;
		btn.backgroundColor = [UIColor blackColor];
		self.selectedBtn = btn;
		[self.delegate hotsSelectionViewBtnClick:btn];
	}	
}

@end
